const { sqlite3 } = require('../../mysql')

// 获取分类数据
const getCategory = async (ctx) => {
  const category = await sqlite3('category').select()
  ctx.body = {
    category: category,
  }
}

// 获取分类详细价格数据
const getCatedetail =  async (ctx) => {
  console.log(ctx.query.index)
  var id = ctx.query.index
  const categdetail = await sqlite3('category_detail').where({
    cate_id: id
  }).select()
  ctx.body = {
    categdetail: categdetail,
  }
}

// 获取品牌 分类数据
const getCatebrands = async (ctx) => {
  const catebrands = await sqlite3('cate_brands').select()
  var hotbrands = []
  catebrands.forEach((item) => {
    // hotbrands.push(item.hot === 1 ? item : xxx???)
    if (item.hot === 1) {
      hotbrands.push(item)
    }
  })
  ctx.body = {
    hotbrands: hotbrands,
    catebrands: catebrands,
  }
}

// 获取交换流程数据
const getProcess = async (ctx) => {
  const process = await sqlite3('process').select()
  var cut = ''
  var processList = []
  process.forEach((item) => {
    index = process.indexOf(item);
    if (index === 0) {
      cut = item
    } else {
      processList.push(item)
    }
  })
  ctx.body = {
    cut: cut,
    processList: processList,
  }
}

module.exports = { getCategory, getCatedetail, getCatebrands, getProcess }
